import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'CheckBox-CheckboxListTile-带标',
      home: Scaffold(
        appBar: AppBar(
          title: Text('CheckBox-CheckboxListTile-带标'),
        ),
        body: DemoPage(),
      ),
    );
  }
}

class DemoPage extends StatefulWidget{
  @override
  DemoPageState createState() => DemoPageState();
}

class DemoPageState extends State{

  var _vulue = false;

  void _vulueChanged(bool? value){
    for(var i=0;i<isChecks.length;i++){
      isChecks[i] = value!;
      setState(() {
        _vulue = value!;
      });
    }
  }

  bool isCheck = false;

  List<bool> isChecks = [false,false,false,false];

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        CheckboxListTile(
            value: isChecks[0],
            //默认文字是否高亮
            selected: true,
            onChanged:(bool){
              setState(() {
                isChecks[0] = bool!;
              });
            },
          dense: false,//文字是否对齐，图标高度
            ////文字是否三行显示
            isThreeLine:false,
          title: Text('content0'),
          controlAffinity: ListTileControlAffinity.leading,
          subtitle: Text('勾选选项'),
          secondary: Icon(Icons.add),
          activeColor: Colors.red,
        ),
        CheckboxListTile(
          value: isChecks[1],
          //默认文字是否高亮
          selected: true,
          onChanged:(bool){
            setState(() {
              isChecks[1] = bool!;
            });
          },
          dense: false,//文字是否对齐，图标高度
          ////文字是否三行显示
          isThreeLine:false,
          title: Text('content1'),
          controlAffinity: ListTileControlAffinity.trailing,
          subtitle: Text('勾选选项'),
          secondary: Icon(Icons.add),
          activeColor: Colors.red,
        ),
        CheckboxListTile(
          value: isChecks[2],
          //默认文字是否高亮
          selected: true,
          onChanged:(bool){
            setState(() {
              isChecks[2] = bool!;
            });
          },
          dense: false,//文字是否对齐，图标高度
          ////文字是否三行显示
          isThreeLine:false,
          title: Text('content2'),
          controlAffinity: ListTileControlAffinity.platform,
          subtitle: Text('勾选选项'),
          // secondary: Icon(Icons.add),
          activeColor: Colors.red,
        ),
        CheckboxListTile(
          value: isChecks[3],
          //默认文字是否高亮
          selected: true,
          onChanged:(bool){
            setState(() {
              isChecks[3] = bool!;
            });
          },
          dense: false,//文字是否对齐，图标高度
          ////文字是否三行显示
          isThreeLine:false,
          title: Text('content3'),
          controlAffinity: ListTileControlAffinity.leading,
          subtitle: Text('勾选选项'),
          secondary: Icon(Icons.add),
          activeColor: Colors.red,
        ),
      ],
    );
  }
}